{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f0cb9ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [\n",
    "    (\"三只松鼠坚果礼包\",56),\n",
    "    (\"马克华菲星光系列\",539),\n",
    "    (\"大吉岭茶\",317),\n",
    "]\n",
    "shopping_car = []\n",
    "zhifubao = input(\"请输入支付宝余额:\")\n",
    "# 购物车商品选择\n",
    "if zhifubao.isdigit():\n",
    "    zhifubao = int(zhifubao)\n",
    "    while True:\n",
    "        for item in product_list:\n",
    "            print(product_list.index(item),item)\n",
    "        choice = input(\"请选择您要购买的商品序号：\")\n",
    "        #商品的选择\n",
    "        if choice.isdigit():\n",
    "            choice = int(choice)\n",
    "            if choice >= 0 and choice < 8:\n",
    "                if zhifubao >= product_list[choice][1]:\n",
    "                    zhifubao = zhifubao - product_list[choice][1]\n",
    "                    shopping_car.append(product_list[choice])\n",
    "                    print(\"您已把商品%s成功添加到购物车，您的支付宝余额是%s:\"%(product_list[choice][0],zhifubao))\n",
    "                else:\n",
    "                    print(\"您的支付宝余额不足，请看看别的\")\n",
    "            else:\n",
    "                print(\"商品列表里面没有这个商品，请重新选择一个商品\")\n",
    "        elif choice ==\"q\":\n",
    "            print(\"-----购物车清单-----\")\n",
    "            for i in shopping_car:\n",
    "                print(item)\n",
    "            print(\"支付宝余额%s:\"% zhifubao)\n",
    "            break\n",
    "        else:\n",
    "            print(\"按q退出程序\")\n",
    "else:\n",
    "    print(\"请输入数字\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
